package com.terrynoya.qtree
{
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;

	/**
	 * 
	 * @author TerryYao
	 */
	public class QTree
	{
		private var _root:QTreeNode;
		
		/**
		 * 
		 * @default 
		 */
		public static const MIN_WIDTH:Number = 10;
		
		/**
		 * 
		 */
		public function QTree()
		{
			
		}
		
		/**
		 * 显示到舞台上
		 * @param canvas
		 */
		public function draw(canvas:Sprite):void
		{
			this._root.drawGrid(canvas);
		}
		
		/**
		 * 在qwsa所圈定的方形中生成一个四叉树
		 * @param q
		 * @param w
		 * @param s
		 * @param a
		 * @return 
		 */
		public function generate(q:Point,w:Point,s:Point,a:Point):QTreeNode
		{
			this._root = new QTreeNode(q,w,s,a);
			return this._root;
		}
		
		/**
		 * 定位一个显示对象
		 * 将显示对象加入四叉树中
		 * @param obj
		 */
		public function locate(obj:DisplayObject):void
		{
			var noteItem:QTreeNoteItem = new QTreeNoteItem(obj);
			this._root.locate(noteItem);
 		} 
		
		/**
		 * 
		 */
		public function detect():void
		{
			this._root.detect();
		}
	}
}